﻿<%@ Page Title="" Language="C#" MasterPageFile="~/admin.Master" AutoEventWireup="true" CodeBehind="ActionAdd.aspx.cs" Inherits="yedian.ActionAdd" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link rel="stylesheet" href="/kindeditor/themes/default/default.css" />
    <link rel="stylesheet" href="/kindeditor/plugins/code/prettify.css" />
    <script charset="utf-8" type="text/javascript" src="/kindeditor/kindeditor-min.js"></script>
    <script charset="utf-8" type="text/javascript" src="/kindeditor/lang/zh_CN.js"></script>
    <script charset="utf-8" type="text/javascript" src="/kindeditor/plugins/code/prettify.js"></script>

    <style type="text/css">
       #action_table .box {
            width: 20px;
            height: 20px;
            padding: 2px;
            border: 1px solid #ccc;
            border-radius: 2px;
        }

       #action_table ul {
            list-style: none;
            padding: 0px;
            margin: 0px;
            border-top: 0px;
            font-size: 12px;
        }

          #action_table ul li {
                display: block;
                float: left;
                text-indent: 2em;
            }
    </style>
    <script type="text/javascript">
        KindEditor.ready(function (K) {
            var editor1 = K.create('#<%=NewsContent.ClientID %>', {
                cssPath: '/kindeditor/plugins/code/prettify.css',
                uploadJson: 'HandlerUpload.r',
                fileManagerJson: 'HandlerFileManager.r',
                allowFileManager: true,
                afterCreate: function () {
                    var self = this;
                }
            });
            prettyPrint();
        });

        function tj() {
            if ($("#ctl00_ContentPlaceHolder1_fNewsTitle").val() == "" || $("#ctl00_ContentPlaceHolder1_fNewsTitle").val() == null) {
                ShowDialog("活动名称不能为空!");
                return false;
            }
            if ($("#ctl00_ContentPlaceHolder1_facePic").val() == "" || $("#ctl00_ContentPlaceHolder1_facePic").val() == null) {
                ShowDialog("活动封面不能为空!");
                return false;
            }
            if ($("#ctl00_ContentPlaceHolder1_actionAddress").val() == "" || $("#ctl00_ContentPlaceHolder1_actionAddress").val() == null) {
                ShowDialog("活动地点不能为空!");
                return false;
            }
            if ($("#ctl00_ContentPlaceHolder1_date1").val() == "" || $("#ctl00_ContentPlaceHolder1_date1").val() == null) {
                ShowDialog("活动开始时间不能为空!");
                return false;
            }
            if ($("#ctl00_ContentPlaceHolder1_date2").val() == "" || $("#ctl00_ContentPlaceHolder1_date2").val() == null) {
                ShowDialog("活动结束时间不能为空!");
                return false;
            }
            if ($("#ctl00_ContentPlaceHolder1_actionTickSM").val() == "" || $("#ctl00_ContentPlaceHolder1_actionTickSM").val() == null) {
                ShowDialog("购票须知不能为空!");
                return false;
            }
            if ($("#ctl00_ContentPlaceHolder1_NewsContent").val() == "" || $("#ctl00_ContentPlaceHolder1_NewsContent").val() == null) {
                ShowDialog("活动说明不能为空!");
                return false;
            }
            var tickList = new Array();
            $("#ctl00_ContentPlaceHolder1_tickJson").val('');
            $("#mytable tbody").find("tr").each(function () {
                var tdArr = $(this).children();
                tickModel = { "name": tdArr.eq(0).text(), "pice": tdArr.eq(1).text(), "num": tdArr.eq(2).text(), "time": tdArr.eq(3).text() };
                tickList.push(tickModel);
            });
            $("#ctl00_ContentPlaceHolder1_tickJson").val(JSON.stringify(tickList));
            if ($("#ctl00_ContentPlaceHolder1_tickJson").val() == "" || $("#ctl00_ContentPlaceHolder1_tickJson").val() == null) {
                ShowDialog("请输入活动票!");
                return false;
            }
            return true;
        }
        function imgFace(fileDom, view, hidpic) {
            //判断是否支持FileReader
            if (window.FileReader) {
                var reader = new FileReader();
            } else {
                ShowDialog("您的设备不支持图片预览功能，如需该功能请升级您的设备!");
            }

            //获取文件
            var file = fileDom.files[0];
            var imageType = /^image\//;
            //是否是图片
            if (!imageType.test(file.type)) {
                ShowDialog("请选择图片！");
                return;
            }
            //读取完成
            reader.onload = function (e) {
                //获取图片dom
                var img = document.getElementById(view);
                //图片路径设置为读取的图片
                img.src = e.target.result;
            };
            reader.readAsDataURL(file);
            doUpload(fileDom, hidpic)
        }
        function doUpload(fileDom, hidpic) {
            var formData = new FormData();
            formData.append("Filedata", fileDom.files[0]);
            $.ajax({
                url: '/user/uploadPhoto.aspx',  /*这是处理文件上传的servlet*/
                type: 'POST',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (returndata) {
                    var jsonData = eval("(" + returndata + ")");
                    if (jsonData.success == "true") {
                        document.getElementById(hidpic).value = jsonData.filePath;
                    }
                    else {
                        ShowDialog(jsonData.msg);
                    }
                },
                error: function (returndata) {
                    ShowDialog(returndata);
                }
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <input type="hidden" name="tickJson" runat="server" id="tickJson" />
    <div id="action_table">
        <div id="breadcrumb">
            <a href="#" title="Go to Home" class="tip-bottom"><i class="icon-home"></i>Home</a>
            <a href="#" class="current">编辑活动</a>
        </div>
        <ul>
            <li style="width: 0%;"></li>
            <li style="width: 100%;">
                <h4 style="font-weight: bold">活动页面内容编辑&nbsp;&nbsp;<span style="color: #1E90FF;"><asp:Literal ID="errinfo" runat="server"></asp:Literal></span></h4>
            </li>
        </ul>
        <ul>
            <li style="width: 10%;">活动名称</li>
            <li style="width: 90%;">
                <input type="text" name="fNewsTitle" id="fNewsTitle" runat="server" maxlength="200" style="width: 280px;" /><span style="color: Red;">* </span></li>
        </ul>
        <ul>
            <li style="width: 10%;">活动封面</li>
            <li style="width: 90%;">
                <input type="file" name="file_face" onchange="imgFace(this,'faceView','ctl00_ContentPlaceHolder1_facePic')" />
        <input type="hidden" name="facePic" runat="server" id="facePic" />
        <img src="" width="100px" id="faceView" >

            </li>
        </ul>
        <ul>
            <li style="width: 10%;">活动地点</li>
            <li style="width: 90%;">
                <input type="text" name="actionAddress" id="actionAddress" runat="server" maxlength="200" style="width: 280px;" /><span style="color: Red;">* </span></li>
        </ul>
        <ul>
            <li style="width: 10%;">开始时间</li>
            <li style="width: 90%;">
                <asp:TextBox ID="date1" Width="100px" onfocus="WdatePicker()" runat="server"></asp:TextBox>
                结束时间：<asp:TextBox ID="date2" Width="100px" onfocus="WdatePicker()" runat="server"></asp:TextBox></li>
        </ul>
        <ul>
            <li style="width: 10%;">活动票</li>
            <li style="width: 90%;"><a class="btn btn-info" id="add" style=" text-align:center;text-indent: 0em;">添加新的票</a>
            </li>
        </ul>
        <ul>
            <li style="width: 5%;"></li>
            <li style="width: 95%;">
                <table class="table table-bordered table-striped" id="mytable">
                    <thead>
                        <tr>
                            <td>名称</td>
                            <td>价格</td>
                            <td>数量</td>
                            <td>截至购买时间</td>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>早鸟票</td>
                            <td>50</td>
                            <td>100</td>
                            <td>2018-10-30</td>
                        </tr>
                    </tbody>
                </table>
            </li>
        </ul>
        <ul>
            <li style="width: 10%;">购票须知</li>
            <li style="width: 90%;">
                <textarea rows="3" cols="20" name="actionTickSM" id="actionTickSM" runat="server">
</textarea><span style="color: Red;">* </span></li>
        </ul>
        <ul>
            <li style="width: 0%;"></li>
            <li style="width: 100%;">
                <textarea id="NewsContent" name="NewsContent" runat="server" cols="100" rows="8" style="width: 99%; height: 320px; visibility: hidden;"></textarea></li>
        </ul>
        <ul>
            <li style="width: 5%;"></li>
            <li style="width: 95%;">
                <asp:Button ID="Button1" OnClientClick="return tj();" runat="server" Text="保存" OnClick="Button1_Click" class="btn btn-success" /></li>
        </ul>

    </div>
    <script src="js/jquery-1.11.0.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="js/bootstable.js"></script>
    <script type="text/javascript">
        $('#mytable').SetEditable({
            $addButton: $('#add')
        });
    </script>
</asp:Content>
